import Vue from 'vue'
import Vuex from 'vuex'
import axios from 'axios'

Vue.use(Vuex)

export default new Vuex.Store({
    state: {
        cityID: '310100',
        cityName: '上海',
        cinemaList: [],
    },
    mutations: {
        changeCityName(state, name) {
            this.state.cityName = name
        },
        changeCityID(state, id) {
            this.state.cityID = id
        },
        setCinemaList(state, cinemalist) {
            state.cinemaList = cinemalist
        },
        clearCinemaList(state) {
            state.cinemaList = []
        }
    },
    actions: {
        getCinemaList(store, cityID) {
            return axios({
                url: `https://m.maizuo.com/gateway?cityId=${cityID}&ticketFlag=1&k=5184233`,
                headers: {
                    'X-Client-Info': '{"a":"3000","ch":"1002","v":"5.0.4","e":"1614558948631982962769921","bc":"310100"}',
                    'X-Host': 'mall.film-ticket.cinema.list',
                    'X-Requested-With': 'XMLHttpRequest',
                },
            }).then(res => {
                store.commit('setCinemaList', res.data.data.cinemas);
            }).catch(err => {
                console.log('错误', err);
            })
        },
    },

    modules: {

    }
})
